﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace WinFormClientApp
{
    public partial class Form1 : Form
    {
        // remoteobject reference
        private RemotingObjects.IRemoteObject remoteObject;
        public Form1()
        {
            try
            { //channel establishement and remote object connection
                TcpChannel channel = new TcpChannel();
                ChannelServices.RegisterChannel(channel, true);
                remoteObject = (RemotingObjects.IRemoteObject)
                    Activator.GetObject(typeof(RemotingObjects.IRemoteObject),
                    "tcp://localhost:12000/HostObject");

            }
            catch
            {
                MessageBox.Show("Error connecting to the server");
            }
            InitializeComponent();
            
        }

        private void label1_Click(object sender, EventArgs e)
        {
            if (remoteObject != null)
            {
                String result = remoteObject.sayHELLO(textBox1.Text);
                MessageBox.Show("Result from remote object: " + result);
            }
            else MessageBox.Show("Error remote object not available");
        }
    }
}
